'use strict';
const dayjs = require('dayjs');
module.exports = app => {
    const { STRING, INTEGER, DECIMAL, DATE } = app.Sequelize;
    const Model = app.model.define(
      'recharge',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          name: STRING(255),
          tokens: INTEGER,
          user_id: INTEGER,
          amount: DECIMAL(10, 2),
          create_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
              },
          },
      },
      {
          tableName: 'recharge',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
    );
    Model.associate = function() {
        app.model.Recharge.belongsTo(app.model.User, {foreignKey: 'user_id', targetKey: 'id'});
    }
    return Model;
};
